package com.szr.leex.dao.converter;

import org.hibernate.dialect.Dialect;
import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.DiscriminatorType;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.sql.CharTypeDescriptor;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;

import com.szr.leex.dao.converter.type.java.GenderTypeDescriptor;
import com.szr.leex.po.enums.GenderEnum;

/**
 * GenderType for Gender
 * 两种类型的custom basic type 之一，extend BasicType，并且需要注册
 * Created by WangChen on 2018/9/4 18:03.
 */
public class GenderType extends AbstractSingleColumnStandardBasicType<GenderEnum> implements DiscriminatorType<GenderEnum>{

    public static final GenderType INSTANCE = new GenderType();

    public GenderType(){
        super(CharTypeDescriptor.INSTANCE, GenderTypeDescriptor.INSTANCE);
    }

    public GenderType(SqlTypeDescriptor sqlTypeDescriptor, JavaTypeDescriptor<GenderEnum> javaTypeDescriptor) {
        super(sqlTypeDescriptor, javaTypeDescriptor);
    }

    @Override
    public GenderEnum stringToObject(String s) throws Exception {
        return fromString(s);
    }

    @Override
    public String objectToSQLString(GenderEnum genderEnum, Dialect dialect) throws Exception {
        return toString(genderEnum);
    }

    @Override
    public String getName() {
        return "com.szr.leex.dao.converter.GenderType";
    }
}
